package org.healer.simple_juc;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.concurrent.*;

public class TestCallabel implements Callable<Boolean> {

    private String url;
    private String name;

    public TestCallabel(String url,String name){
        this.url=url;
        this.name=name;
    }
    @Override
    public Boolean call() throws Exception {
        WebDownloader wd=new WebDownloader();
        wd.Downloader(url,name);
        System.out.println("下载了文件"+name);
        return true;
    }
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        TestCallabel t1=new TestCallabel("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fnews.yunnan.cn%2Fpic%2F003%2F038%2F125%2F00303812512_6f4574f3.jpg&refer=http%3A%2F%2Fnews.yunnan.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1624427903&t=b89b5d6a5a90166d8a53dae85f65bbf5","袁隆平1.jpg");
        TestCallabel t2=new TestCallabel("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimgpolitics.gmw.cn%2Fattachement%2Fjpg%2Fsite2%2F20210522%2Ff44d305ea0d8221328f424.jpg&refer=http%3A%2F%2Fimgpolitics.gmw.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1624427903&t=33b7888d21ff885c6c9a6acdc9906ff6","袁隆平2.jpg");
        TestCallabel t3=new TestCallabel("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimgpolitics.gmw.cn%2Fattachement%2Fjpg%2Fsite2%2F20210522%2Ff44d305ea0d82213299150.jpg&refer=http%3A%2F%2Fimgpolitics.gmw.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1624427903&t=2a46222fb05b2c036b8240b957fae89c","袁隆平3.jpg");
        //创建执行服务
        ExecutorService ser = Executors.newFixedThreadPool(3);
        // 提交执行
        Future<Boolean> r1=ser.submit(t1);
        Future<Boolean> r2=ser.submit(t2);
        Future<Boolean> r3=ser.submit(t3);
        //获取结果
        Boolean aBoolean1 = r1.get();
        Boolean aBoolean2 = r2.get();
        Boolean aBoolean3 = r3.get();
        //关闭服务
        ser.shutdown();
    }
}
